<template>
    <div>
        <table border="1" align="center" width="600px">
            <tr>
                <th>名称</th>
                <th>车牌号</th>
                <th>进入时间</th>
                <th colspan="2">操作</th>
            </tr>
            <tr v-for="record in recordList">
                <th>{{record.user.name}}</th>
                <th>{{record.user.title}}</th>
                <th>{{record.start}}</th>
                <th><button @click="putUser(record.user.id)" v-if="record.user.level==0">升级为业主</button> <button v-else>小区业主</button></th>
                <th><button @click="logout(record.id)">离开</button></th>
            </tr>
        </table>
        <router-link to="/login_park">小区门口</router-link>
        <router-link to="/record_park">查询</router-link>
    </div>
</template>

<script>
    export default {
        name: "park_park",
        data() {
            return {
                recordList: [],
                park_id: this.$route.query.park_id,
            }
        },
        created() {
            this.$axios({
                url: 'park/record/',
                params: {
                    park_id: this.park_id
                }
            }).then(resp=>{
                this.recordList = resp.data
            })
        },
        methods: {
            logout(id){
                this.$axios({
                    url: 'park/record/',
                    method: 'PUT',
                    data: {
                        record_id: id
                    }
                }).then(resp=>{
                    alert(resp.data.msg);
                    if (resp.data.code==200){
                        this.$router.go(0)
                    }
                })
            },
            putUser(id){
                this.$axios({
                    url: 'park/user/',
                    method: 'PUT',
                    data: {
                        user_id: id
                    }
                }).then(resp=>{
                    alert(resp.data.msg);
                    if (resp.data.code==200){
                        this.$router.go(0)
                    }
                })
            },

        },
        computed: {},
        filters: {},
        watch: {},
    }
</script>

<style scoped>

</style>
